package com.neutech.maplestory.entity;

import com.neutech.maplestory.client.MapleStoryClient;
import com.neutech.maplestory.util.ImageUtil;

import java.awt.*;

public class Mob extends AbstractMapleStoryObject{
    public static Image[] imgs = new Image[100];
    static {
        for (int i = 0; i < 3; i++) {
            imgs[i] = ImageUtil.getImage("mob01_left_stand" + i);
        }
        for (int i = 3; i < 6; i++) {
            imgs[i] = ImageUtil.getImage("mob01_left_walk" + (i - 3));
        }
        for (int i = 6; i < 9; i++) {
            imgs[i] = ImageUtil.getImage("mob01_left_die" + (i - 7));
        }
    }
    public Mob(){
        this.width = imgs[0].getWidth(null);
        this.height = imgs[0].getHeight(null);
        this.dir = Direction.LEFT;
        //怪物图片状态
        this.action = Action.STAND                                       ;
        this.live = true;
//        this.speed = 5;
    }

    public Mob(MapleStoryClient msc,int x, int y, int speed){
        this();
        this.msc = msc;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    private int count;
    private int step;
    private int dieStep;
    @Override
    public void draw(Graphics g) {
        if (dieStep >= 4){
            this.live = false;
            dieStep = 0;
        }
        if (!live){
            msc.mobs.remove(this);
            return;
        }
        switch (dir){
            case LEFT:
                switch (action){
                    case STAND:
                        if (count++ % 3 == 0){
                            g.drawImage(imgs[step++ % 3],x, y, null);
                        }else {
                            g.drawImage(imgs[step % 3],x, y, null);
                        }
                        break;
                    case WALK:
                        if (count++ % 3 == 0){
                            g.drawImage(imgs[step++ % 3 + 3 ],x, y, null);
                        }else {
                            g.drawImage(imgs[step % 3 + 3],x, y, null);
                        }
                        break;
                    case DIE:
                        if (count++ % 3 == 0){
                            g.drawImage(imgs[dieStep++ % 3 + 6],x, y, null);
                        }else {
                            g.drawImage(imgs[dieStep % 3 + 6],x, y, null);
                        }
                    default:
                        break;
                }
                break;
            default:
                break;
        }
        move();
    }
    @Override
    public void move(){
        switch (dir){
            case LEFT:
                switch (action){
                    case WALK:
                        this.x -= speed;
                        break;
                    default:
                        break;
                }
                break;
            case RIGHT:
                this.x += speed;
                break;
            default:
                break;
        }
    }
}
